home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / main / url.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-22  |  2.7 KB  |  133 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1994,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. ****************************************************************/
  13. #include <ctype.h>
  14. #include "TelnetHeader.h"
  15.  
  16. #include "rsinterf.proto.h"
  17. #include "url.proto.h"
  18.  
  19. #if 0
  20. Boolean MyStrNEqual (char *s1, char *s2, short n)
  21. {
  22.     unsigned char *t = gTable;
  23.     unsigned char *us1 = (unsigned char *)s1;
  24.     unsigned char *us2 = (unsigned char *)s2;
  25.  
  26.     while (--n >= 0 && t[*us1++] == t[*us2++]) /* do nothing */;
  27.     return n < 0;
  28. }
  29.  
  30. static Boolean IsFTPURL (char *obj)
  31. {
  32.     char *p;
  33.     
  34.     if (MyStrNEqual(obj, "ftp:", 4)) return true;
  35.     p = obj;
  36.     while (*p != '.' && *p != 0) p++;
  37.     if (*p == 0) return false;
  38.     p++;
  39.     while (*p != ':' && *p != '/' && *p != 0) p++;
  40.     if (*p == 0) return false;
  41.     
  42.     p = strstr(obj, "://");
  43.     if (p == nil) return true;
  44.     if (MyStrNEqual(obj, "ftp://", 6)) return true;
  45.     return false;
  46. }
  47.  
  48. static Boolean IsEmailAddress (CStr255 obj)
  49. {
  50.     char *p;
  51.     
  52.     if (MyStrNEqual(obj, "mailto:", 7)) return true;
  53.     for (p = obj; *p != 0; p++) {
  54.         if (*p == '@') {
  55.             for (p++; *p != 0; p++) if (*p == '.') return true;
  56.             return false;
  57.         }
  58.     }
  59.     return false; 
  60. }
  61. #endif
  62.  
  63. #define isLWSP(a) ((a) == ' ' || (a) == '\t')
  64. #define isLWSPorCR(a) (isLWSP(a) || (a) == CR)
  65.  
  66. void    ParseURL(short w)
  67. {
  68.     char *textEnd, *p, *q, *x, *y;
  69.     long len;
  70.     Handle urlH;
  71.     
  72.     urlH = RSGetTextSel(w, 0);
  73.     if ((urlH == (char **)-1L) || (urlH == nil)) {
  74.         return;
  75.         }
  76.     
  77.     HLock(urlH);
  78.     
  79.     p = *urlH;
  80.     q = *urlH + GetHandleSize(urlH) - 1;
  81.     
  82.     textEnd = *urlH + GetHandleSize(urlH);
  83.     
  84.     while (p >= *urlH && !isLWSPorCR(*p) && *p != '<') p--;
  85.     if (*p != '<') {
  86.         p++;
  87.         while (p < q && !isalnum(*p) && *p != '<') p++;
  88.     }
  89.     
  90.     while (q < textEnd && !isLWSPorCR(*q) && *q != '>') q++;
  91.     if (*q != '>') {
  92.         q--;
  93.         while (q > p && !isalnum(*q) && *q != '/' && *q != '>') q--;
  94.     }
  95.     
  96.     if (p >= q) return /*kNotURL*/;
  97.     
  98.     while (p < q && isLWSPorCR(*p)) p++;
  99.     while (p < q && isLWSPorCR(*q)) q--;
  100.         
  101.     len = q - p + 1;
  102. //    if (len > 255) return kNotURL;
  103.     
  104.     for (x = p, y = p; x <= q; x++) {
  105.         if (*x != CR) {
  106.             y++;
  107.             }
  108.         else {
  109.             *y++ = *x;
  110.             }
  111.         }
  112.             
  113.     *y = 0;
  114.     len = y - p;
  115.     if (len == 0) return /*kNotURL*/;
  116.     
  117. //    *urlBegin = p - **urlH;
  118. //    *urlEnd = q - **urlH + 1;
  119.     
  120.     if (len >= 2 && *p == '<' && *q == '>') {
  121.         len -= 2;
  122.         BlockMoveData(p+1, p, len);
  123.         p[len] = 0;
  124.     }
  125.     
  126. //    if (IsFTPURL(url)) return kFtpURL;
  127.     
  128. //    if (IsEmailAddress(url)) return kEmailURL;
  129.     
  130.     DisposeHandle(urlH);
  131.     return /*kNotURL*/;
  132.  
  133. }